﻿module.exports = function (grunt)
{
	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		concat: {
			options: {
				separator: '\n\r'
			},
			debug: {
				files:
				[
					{
						src:
						[
							"js/src/intro.js",
							"js/src/core.js",
							"js/src/controls.navigation.js",
							"js/src/controls.cartStatusBtn.js",
							"js/src/controls.subnavigation.js",
							"js/src/pages.home.js",
							"js/src/pages.product.listing.js",
							"js/src/pages.product.detail.js",
							"js/src/pages.storelocator.js",
							"js/src/pages.search.js",
							"js/src/pages.checkout.details.js",
							"js/src/pages.checkout.payment.js",
							"js/src/pages.product.detail.em.models.js",
							"js/src/pages.product.detail.em.views.js",
							"js/src/pages.product.detail.em.controllers.js",
							"js/src/outro.js"
						],
						dest: 'js/dist/<%= pkg.name %>.js',
						nonull: true
					},
					{
						src:
						[
							"js/libs/jquery-migrate-1.1.1.min.js",
							"js/libs/jquery.flexslider.js",
							"js/libs/handlebars.js",
							"js/libs/ember-1.0.0-rc.3.js",
							"js/libs/galleria/galleria-1.2.8.js",
							"js/libs/jqModal.js",
							"js/libs/iphone-style-checkboxes.js",
							"js/libs/jquery.tappable.js",
							"js/libs/Codagenic.store-1.0.1.debug.js",
							'js/dist/<%= pkg.name %>.js'
						],
						dest: 'js/dist/<%= pkg.name %>.debug.js',
						nonull: true
					}
				]
			},
			release: {
				options:
				{
					separator: ';\n\r'
				},
				src:
				[
					"js/libs/jquery-migrate-1.1.1.min.js",
					"js/libs/jquery.flexslider-min.js",
					"js/libs/handlebars.min.js",
					"js/libs/ember-1.0.0-rc.3.min.js",
					"js/libs/galleria/galleria-1.2.8.min.js",
					"js/libs/jqModal.min.js",
					"js/libs/iphone-style-checkboxes.min.js",
					"js/libs/jquery.tappable.min.js",
					"js/libs/Codagenic.store-1.0.1.min.js",
					'js/dist/<%= pkg.name %>.min.js'
				],
				dest: 'js/dist/<%= pkg.name %>.release.js',
				nonull: true
			}
		},
		jshint: {
			options: {
				smarttabs: true,
				curly: true,
				eqeqeq: true,
				eqnull: true,
				browser: true,
				globals: {
					jQuery: true
				}
			},
			beforeconcat: ["gruntfile.js", "js/src/**/*.js", "!js/src/intro.js", "!js/src/outro.js"],
			afterconcat: ["js/dist/<%= pkg.name %>.js"]
		},
		uglify: {
			options: {
				mangle: {
					except: ['jQuery', 'ember']
				},
				sourceMap: 'js/dist/<%= pkg.name %>.source-map.js',
				compress: true,
				report: 'min',
				preserveComments: 'some',
				banner:
					'\n/*!* <%= pkg.name %> v<%= pkg.version %> \n'+
					'Author: Codagenic \n\n' +
					'Licenced under the MIT License (MIT) \n\n' +
					'Copyright (C) 2011 - 2012 Codagenic Pty. Ltd \n\n' +
					'Permission is hereby granted, free of charge, to any person obtaining a copy\n'+
					'of this software and associated documentation files (the "Software"), to deal\n'+
					'in the Software without restriction, including without limitation the rights\n'+
					'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n'+
					'copies of the Software, and to permit persons to whom the Software is\n'+
					'furnished to do so, subject to the following conditions:\n\n'+
					'The above copyright notice and this permission notice shall be included in\n'+
					'all copies or substantial portions of the Software.\n\n'+
					'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n'+
					'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n'+
					'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n'+
					'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n'+
					'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n'+
					'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n'+
					'THE SOFTWARE.\n\n'+
					'*/'
			},
			blanc:
			{
				files: {
				'js/dist/<%= pkg.name %>.min.js': ['js/dist/<%= pkg.name %>.js']
				}
			}
		},
		sass: {
			debug: {
				options: {
					style: 'nested',
					debugInfo: true,
					lineNumbers: true
				},
				files: {
					'Css/styles.debug.css': 'Css/styles.scss'
				}
			},
			release: {
				options: {
					style: 'compressed',
					debugInfo: false,
					lineNumbers: false
				},
				files: {
					'Css/styles.release.css': 'Css/styles.scss'
				}
			}
		},
		clean: [
			"js/dist/",
			"Css/styles.release.css"
		]
	});


	// Load the plugins
	grunt.loadNpmTasks('grunt-contrib-concat');
	grunt.loadNpmTasks('grunt-contrib-jshint');
	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-sass');
	grunt.loadNpmTasks('grunt-contrib-clean');

	// Task(s).
	grunt.registerTask('default', ['jshint:beforeconcat', 'concat:debug', 'jshint:afterconcat', 'uglify', 'sass', 'concat:release']);
	grunt.registerTask('build', 'default');


};